package cn.iocoder.yudao.module.wengfu.service.result;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.wengfu.controller.admin.result.vo.*;
import cn.iocoder.yudao.module.wengfu.dal.dataobject.result.LaboratoryResultInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.wengfu.dal.mysql.result.LaboratoryResultInfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.wengfu.enums.ErrorCodeConstants.*;

/**
 * 化验结果 Service 实现类
 *
 * @author yzs
 */
@Service
@Validated
public class LaboratoryResultInfoServiceImpl implements LaboratoryResultInfoService {

    @Resource
    private LaboratoryResultInfoMapper laboratoryResultInfoMapper;

    @Override
    public Long createLaboratoryResultInfo(LaboratoryResultInfoSaveReqVO createReqVO) {
        // 插入
        LaboratoryResultInfoDO laboratoryResultInfo = BeanUtils.toBean(createReqVO, LaboratoryResultInfoDO.class);
        laboratoryResultInfoMapper.insert(laboratoryResultInfo);

        // 返回
        return laboratoryResultInfo.getId();
    }

    @Override
    public void updateLaboratoryResultInfo(LaboratoryResultInfoSaveReqVO updateReqVO) {
        // 校验存在
        validateLaboratoryResultInfoExists(updateReqVO.getId());
        // 更新
        LaboratoryResultInfoDO updateObj = BeanUtils.toBean(updateReqVO, LaboratoryResultInfoDO.class);
        laboratoryResultInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteLaboratoryResultInfo(Long id) {
        // 校验存在
        validateLaboratoryResultInfoExists(id);
        // 删除
        laboratoryResultInfoMapper.deleteById(id);
    }

    @Override
        public void deleteLaboratoryResultInfoListByIds(List<Long> ids) {
        // 删除
        laboratoryResultInfoMapper.deleteByIds(ids);
        }


    private void validateLaboratoryResultInfoExists(Long id) {
        if (laboratoryResultInfoMapper.selectById(id) == null) {
            throw exception(LABORATORY_RESULT_INFO_NOT_EXISTS);
        }
    }

    @Override
    public LaboratoryResultInfoDO getLaboratoryResultInfo(Long id) {
        return laboratoryResultInfoMapper.selectById(id);
    }

    @Override
    public PageResult<LaboratoryResultInfoDO> getLaboratoryResultInfoPage(LaboratoryResultInfoPageReqVO pageReqVO) {
        return laboratoryResultInfoMapper.selectPage(pageReqVO);
    }

    @Override
    public LaboratoryResultInfoDO getLaboratoryResultInfoByTestId(String testId) {
        return laboratoryResultInfoMapper.selectByTestId(testId);
    }

}
